import java.util.Scanner;

class SQueue<E>{
    E[] data ; //存放数据
    int front;
    int count;


    /* 请在这里填写答案 */
    public SQueue(int n) {
        data = (E[])new Object[n];
        front = 0;
        count = 0;
    }

    public boolean empty(){
        return count==0;
    }

    public void EnQueue(E e) {
        int pos = (front+count) % data.length;
        if (count==data.length) {
            throw new IllegalArgumentException("FULL");
        }else {
            count++;
            data[pos] = e;
        }
    }

    public E DeQueue(){
        if(empty()){
            throw new IllegalArgumentException("NULL");
        }else {
            int ret = front;
            front = (front + 1) % data.length;
            count--;
            return data[ret];
        }
    }

}
public class Main5 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        SQueue<Integer> Q = new SQueue<Integer>(n); //创建存储空间大小为n的队列
        String cmd = sc.next();
        while(!cmd.equals("E")) {
            if(cmd.equals("I")) {
                try {
                    int x = sc.nextInt();
                    Q.EnQueue(x);
                }
                catch(IllegalArgumentException e) {
                    System.out.println(e.getMessage());
                }
            }
            else {
                try{
                    int x = Q.DeQueue();
                    System.out.println(x);
                }
                catch(IllegalArgumentException e) {
                    System.out.println(e.getMessage());
                }
            }
            cmd = sc.next();
        }
        sc.close();
    }

}

